<template>
  <div class="msg" :style="'animation-duration:' + time + 'ms'">{{ msg }}</div>
</template>

<script>
export default {
  data() {
    return {
      msg: "默认消息",
      time: 3000,
    };
  },
};
</script>

<style scoped>
.msg {
  margin-top: 10px;
  background-color: green;
  color: white;
  font-size: 12px;
  padding: 4px 16px;
  border-radius: 6px;
  box-shadow: 0px 0px 8px #ccc;
  transform: translate(0, -100%);
  opacity: 0;
  animation: showMsg 3s ease;
}
@keyframes showMsg {
  0% {
    transform: translate(0, -100%);
    opacity: 0;
  }
  10% {
    transform: translate(0, 0);
    opacity: 1;
  }
  90% {
    transform: translate(0, 0);
    opacity: 1;
  }
  100% {
    transform: translate(0, -100%);
    opacity: 0;
  }
}
</style>